package com.zego.wawaji.ui.wawa;

import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.View;

import com.zego.wawaji.base.bean.Common;
import com.zego.wawaji.base.bean.Updata;
import com.zego.wawaji.base.log.PSP;
import com.zego.wawaji.base.log.PToast;
import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.base.observer.ModuleBase;
import com.zego.wawaji.base.observer.MsgMgr;
import com.zego.wawaji.base.observer.MsgType;
import com.zego.wawaji.base.utils.InputUtils;
import com.zego.wawaji.base.utils.NetworkUtils;
import com.zego.wawaji.base.utils.TimeUtil;
import com.zego.wawaji.http.request.HttpResponse;
import com.zego.wawaji.http.request.RequestComplete;
import com.zego.wawaji.http.request.UrlParam;
import com.zego.wawaji.message.RecMessageMgr;
import com.zego.wawaji.third.pay.bean.Alipay;
import com.zego.wawaji.third.pay.bean.PayWX;
import com.zego.wawaji.third.pay.util.PayAlipayUtils;
import com.zego.wawaji.third.pay.util.PayWeixinUtils;
import com.zego.wawaji.ui.UIShow;
import com.zego.wawaji.ui.bean.pay.PayList;
import com.zego.wawaji.ui.bean.wawa.Game.Game;
import com.zego.wawaji.ui.bean.wawa.Wawa;
import com.zego.wawaji.ui.bean.wawa.WawaJi;
import com.zego.wawaji.ui.bean.wawa.WawaList;
import com.zego.wawaji.ui.center.transport.bean.StepList;
import com.zego.wawaji.ui.dialog.LoadingDialog;
import com.zego.wawaji.ui.dialog.PickerDialogUtil;
import com.zego.wawaji.ui.play.bean.PlayInit;
import com.zego.wawaji.ui.view.adDialog.AdConstant;
import com.zego.wawaji.ui.view.adDialog.AdManager;
import com.zego.wawaji.ui.view.adDialog.bean.AdInfo;
import com.zego.wawaji.ui.view.adDialog.bean.AdInfoList;
import com.zego.wawaji.ui.view.adDialog.transformer.DepthPageTransformer;
import com.zego.wawaji.wawaji_client.App;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 娃娃相关管理类
 * Created by Su on 2017/11/28.
 */
public class WawaMgr implements ModuleBase {
    private static final String WAWA_LIST = "wawa_list";  // 娃娃种类列表
    private static WawaList wawaList = null;
    private RecMessageMgr messageMgr = new RecMessageMgr();

    @Override
    public void init() {
        messageMgr.init();
    }

    @Override
    public void release() {
    }

    // ========================================== 常量保存 ===============================
    private static WawaJi lastWawaJi;  // 保存用户最近一次进入的房间信息

    public void setLastWawaJi(WawaJi wawaJi) {
        lastWawaJi = wawaJi;
    }

    public WawaJi getLastWawaJi() {
        return lastWawaJi;
    }


    // ========================================== 方法 ===============================

    /**
     * 获取娃娃种类列表
     */
    public WawaList getWawaList() {
        if (wawaList == null) {
            wawaList = new WawaList();
            String result = PSP.getInstance().getString(WAWA_LIST, "");
            if (!TextUtils.isEmpty(result)) {
                wawaList.parseJson(result);
            }
        }
        return wawaList;
    }

    /**
     * 根据娃娃id获取娃娃对象
     */
    public Wawa getWawa(int id) {
        if (!getWawaList().getWawaList().isEmpty()) {
            for (Wawa wawa : getWawaList().getWawaList()) {
                if (wawa.getId() == id) return wawa;
            }
        }
        return new Wawa();
    }

    /**
     * 获取娃娃列表
     */
    public void reqWawaList(final RequestComplete complete) {
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqWawaList, new HashMap<String, Object>(), new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (response.isOk()) {
                    wawaList = (WawaList) response.getBaseData();
                    saveWawaList(response.getResponseString());
                }
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 保存到SP
     */
    private void saveWawaList(String resultStr) {
        PSP.getInstance().put(WAWA_LIST, resultStr);
    }

    /**
     * 获取娃娃机列表
     */
    public void reqWawajiList(final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("limit", 50);
        postParam.put("sortby", "WwjStatus,Id");
        postParam.put("order", "desc,asc");
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqWawajiList, postParam, complete);
    }

    private static PayList payList = new PayList();           // 商品列表

    /**
     * 获取充值列表
     */
    public PayList getPayList() {
        if (payList == null) {
            reqPayListNew(null);
        }
        return payList;
    }

    public void reqPayList(final RequestComplete complete) {
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqPayList, new HashMap<String, Object>(), new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);

                if (response.isOk()) {
                    payList = (PayList) response.getBaseData();
                }
            }
        });
    }

    public void reqPayListNew(final RequestComplete complete) {
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqPayListNew, new HashMap<String, Object>(), new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);

                if (response.isOk()) {
                    payList = (PayList) response.getBaseData();
                }
            }
        });
    }


    /**
     * 获取我的娃娃列表
     *
     * @param status 需查找的列表类型 {@see 'WawaConstant'}
     * @param page   页码，从1开始
     */
    public void reqMyWawa(int status, int page, RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("status", status);
        postParam.put("limit", 10);
        postParam.put("offset", 10 * (page - 1)); // 查找偏移量
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqMyWawa, postParam, complete);
    }

    /**
     * 获取已申请发货娃娃列表
     *
     * @param page 页码，从1开始
     */
    public void reqAskSend(int page, RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("limit", 10);
        postParam.put("offset", 10 * (page - 1)); // 查找偏移量
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqAskSend, postParam, complete);
    }

    /**
     * 获取充值列表
     *
     * @param page 页码，从1开始
     */
    public void reqOrderRecord(int page, RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("limit", 10);
        postParam.put("offset", 10 * (page - 1)); // 查找偏移量
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqOrderRecord, postParam, complete);
    }

    /**
     * 获取消费记录
     *
     * @param page 页码，从1开始
     */
    public void reqSpendRecord(int page, RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("limit", 10);
        postParam.put("offset", 10 * (page - 1)); // 查找偏移量
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqSpendRecord, postParam, complete);
    }

    /**
     * 获取积分记录
     *
     * @param page 页码，从1开始
     */
    public void reqPointRecord(int page, RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("limit", 10);
        postParam.put("offset", 10 * (page - 1)); // 查找偏移量
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqPointRecord, postParam, complete);
    }

    /**
     * 我的娃娃：立即发货
     */
    public void reqSendWawa(long id, final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("game_id", id);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqSendWawa, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                PToast.showShort(response.getMsg());
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 全部发货
     */
    public void reqSendWawaAll(int wawaNum, final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("ww_count", wawaNum);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqSendWawaAll, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
                if (response.isOk()) {
                    PToast.showShort("发货请求成功");
                    MsgMgr.getInstance().sendMsg(MsgType.MT_Wawa_Untreated, null);
                    return;
                }
                PToast.showShort(response.getMsg());
            }
        });
    }

    /**
     * 我的娃娃：兑换娃娃币/积分
     */
    public void reqExchangeWawa(long id, final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("game_id", id);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqExchangeWawa, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);

                if (!response.isOk())
                    PToast.showShort(response.getMsg());
            }
        });
    }

    private static long gameId;     // 游戏id
    public static PlayInit playInit;     // 游戏配置

    /**
     * 游戏预约通知服务器
     */
    public void reqGameApply(long rid, int wwTypeId, final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("ww_type_id", wwTypeId);
        postParam.put("rid", rid);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqGameApply, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (!response.isOk()) {
                    PToast.showShort(response.getMsg());
                } else {
                    playInit = (PlayInit) response.getBaseData();
                }
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 加入游戏房间，通知服务器
     */
    public void reqRoomjoin(long rid, final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("rid", rid);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqRoomjoin, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 开始游戏时通知服务端
     *
     * @param wwTypeId 娃娃id
     */
    public void reqGameAdd(long roomId, int wwTypeId, final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("Rid", roomId);
        postParam.put("WwTypeId", wwTypeId);
        ModuleMgr.getHttpMgr().reqJsonNoCacheHttp(UrlParam.reqGameAdd, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
                if (!response.isOk()) {
                    PToast.showShort(response.getMsg());
                    return;
                }
                Game game = (Game) response.getBaseData();
                gameId = game.getGameId();
                MsgMgr.getInstance().sendMsg(MsgType.MT_Confirm_Board, null); // 通知手动扣费
            }
        });
    }

    public long getGameId() {
        return gameId;
    }

    /**
     * 获取支付宝充值订单
     */
    public void reqAlipay(String subject, int productCode, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "正在获取订单信息");
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("subject", subject);
        postParam.put("product_id", productCode);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqAlipay, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);

                LoadingDialog.closeLoadingDialog();
                if (!response.isOk()) {
                    PToast.showShort(response.getMsg());
                    return;
                }
                Alipay alipay = (Alipay) response.getBaseData();
                new PayAlipayUtils(App.getActivity()).pay(alipay.getUrl());
            }
        });
    }

    /**
     * 获取微信充值订单
     */
    public void reqWXPay(String subject, int productCode, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "正在获取订单信息");
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("subject", subject);
        postParam.put("product_id", productCode);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqWxPay, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);

                LoadingDialog.closeLoadingDialog();
                if (!response.isOk()) {
                    PToast.showShort(response.getMsg());
                    return;
                }
                PayWX payWX = (PayWX) response.getBaseData();
                new PayWeixinUtils(App.getActivity()).pay(payWX);
            }
        });
    }

    /**
     * 检查更新
     *
     * @param adInfo 是否展示广告
     */
    public void reqNewVersion(final boolean show, final boolean adInfo, final RequestComplete complete) {
        ModuleMgr.getHttpMgr().reqGetNoCacheHttp(UrlParam.reqNewVersion, null, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
                LoadingDialog.closeLoadingDialog(200);
                if (response.isOk()) {
                    Updata updata = (Updata) response.getBaseData();
                    if (updata == null) return;
                    if (updata.getVerCode() > ModuleMgr.getAppMgr().getVerCode()) { // 发现新版本
                        PickerDialogUtil.showUpdateDialog((FragmentActivity) App.getActivity(), updata);
                        return;
                    }
                }
                if (show) {
                    PToast.showShort("您当前为最新版本");
                    return;
                }
                signEveryDay();

                // 获取是否有推送广告
                if (adInfo)
                    reqAdInfo();
            }
        });
    }

    public void reqNewVersion(final boolean show, final RequestComplete complete) {
        reqNewVersion(show, true, complete);
    }

    /**
     * 每日签到: 一天请求一次
     */
    public void signEveryDay() {
        if (!TimeUtil.checkDate()) return;

        ModuleMgr.getCenterMgr().reqSign(new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
//                if (response.isOk()) {
//                    TimeUtil.updateCheckDate();
//                    Sign sign = (Sign) response.getBaseData();
//                    PickerDialogUtil.showSignDialog((FragmentActivity) App.getActivity(), sign.getSignedDayWwCoinZs(),
//                            sign.getSignedWeekDays());
//                }
            }
        });
    }


    /**
     * 获取轮播Banner公告
     */
    public void reqBannerNotice(final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("app_id", 1);
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqBannerNotice, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 获取邀请信息
     */
    public void reqShareInfo(final RequestComplete complete) {
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqShareInfo, new HashMap<String, Object>(), new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 积分兑换娃娃币
     */
    public void reqExchangeWwcoin(int point, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "兑换中...");
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("point", point);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqExchangeWwcoin, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                LoadingDialog.closeLoadingDialog();
                if (complete != null)
                    complete.onRequestComplete(response);

                if (response.isOk()) {
                    MsgMgr.getInstance().sendMsg(MsgType.MT_Update_MyInfo, null);
                } else {
                    PToast.showShort(response.getMsg());
                }
            }
        });
    }

    /**
     * 获取物流信息
     *
     * @param tid 内部物流ID
     */
    public void reqTransport(long tid, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "数据获取中...");
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("tid", tid);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqTransport, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                LoadingDialog.closeLoadingDialog();
                if (complete != null)
                    complete.onRequestComplete(response);

                if (!response.isOk()) {
                    PToast.showShort(response.getMsg());
                    return;
                }
                StepList stepList = (StepList) response.getBaseData();
                UIShow.showWaWaLogisticsAct(App.getActivity(), stepList);
            }
        });
    }

    /**
     * 获取最近抓中记录
     */
    public void reqGameCatch(long rid, final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("rid", rid);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqGameCatch, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 分享朋友圈成功奖励，每日一次
     */
    public void reqShareWXCircle(final RequestComplete complete) {
        if (!TimeUtil.checkShareDate()) return;

        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqShareWXCircle, new HashMap<String, Object>(), new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
                if (response.isOk()) {
                    TimeUtil.updateCheckShareDate();
                    ModuleMgr.getCenterMgr().reqMyInfo(null);
                }
            }
        });
    }

    /**
     * 邀请Ip地址通知服务器
     */
    public void reqYQIp() {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("pip", NetworkUtils.ipLine);   // 用户公网IP
        postParam.put("iip", NetworkUtils.getIpAddressString()); // 获取内网IP
        postParam.put("yq_code", InputUtils.getTextFromClip()); // 获取剪切板邀请码
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqYQIp, postParam, null);
    }

    /**
     * 邀请码通知服务器
     */
    public void reqYQCode() {
        String yqCode = InputUtils.getTextFromClip();
        if (TextUtils.isEmpty(yqCode)) {    // 无邀请码
            ModuleMgr.getCenterMgr().reqRewardNew(null);
            return;
        }

        // 邀请码不为数字
        try {
            Long.valueOf(yqCode);
        } catch (Exception e) {
            ModuleMgr.getCenterMgr().reqRewardNew(null);
            return;
        }

        Map<String, Object> postParam = new HashMap<>();
        postParam.put("yq_code", yqCode); // 获取剪切板邀请码
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqYQCode, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                String res = response.getResString();
                if (response.isOk()) {
                    try {
                        if (TextUtils.isEmpty(res)) return;
                        JSONObject jsonObject = new JSONObject(res);
                        int awardNum = jsonObject.optInt("InviteWwCoinZs");
                        if (awardNum > 0) {
                            PickerDialogUtil.showInviteDialog((FragmentActivity) App.getActivity(), awardNum);
                            return;
                        }
                        //PToast.showShort("请求出错");
                    } catch (Exception e) {
                        //PToast.showShort("请求出错");
                    }
                } else {
                    //PToast.showShort(res);
                }

                // 未正确拿到邀请奖励， 执行版本更新
                reqNewVersion(false, null);
            }
        });
    }

    /**
     * 根据参数获取信息
     */
    public void reqAppAboutMsg(final RequestComplete complete) {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("name", "AboutMe");
        ModuleMgr.getHttpMgr().reqPostAndCacheHttp(UrlParam.reqAppMsg, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    /**
     * 获取关于我信息
     */
    public void reqAboutMe(final RequestComplete complete) {
        ModuleMgr.getHttpMgr().reqGetAndCacheHttp(UrlParam.reqAboutMe, null, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);
            }
        });
    }

    private static Common common;

    public Common getCommon() {
        if (common == null) {
            return new Common();
        }
        return common;
    }

    /**
     * 获取基本数据
     */
    public void reqSetting(RequestComplete complete) {
        Map<String, Object> getParam = new HashMap<>();
        getParam.put("rank", 2);
        ModuleMgr.getHttpMgr().reqGetAndCacheHttp(UrlParam.reqSetting, getParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (response.isOk()) {
                    common = (Common) response.getBaseData();
                }
            }
        });
    }

    // ====================================== 广告推送弹框 ===================================

    /**
     * 获取广告弹窗数据
     */
    public void reqAdInfo() {
        if (!TimeUtil.checkAdDate()) return;

        Map<String, Object> getParam = new HashMap<>();
        getParam.put("app_id", "1");
        getParam.put("ver", ModuleMgr.getAppMgr().getVerCode());
        getParam.put("os", "android");
        ModuleMgr.getHttpMgr().reqGetNoCacheHttp(UrlParam.reqAdInfo, getParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (!response.isOk()) return;

                TimeUtil.updateAdDate();
                AdInfoList adInfoList = (AdInfoList) response.getBaseData();
                if (adInfoList == null || adInfoList.getAdInfoList().size() <= 0)
                    return;
                createAdMgr(adInfoList.getAdInfoList());
            }
        });
    }

    public void createAdMgr(List<AdInfo> advList) {
        // 创建广告活动管理对象
        AdManager adManager = new AdManager(App.getActivity(), advList);
        adManager.setOverScreen(true)
                .setPageTransformer(new DepthPageTransformer())
                .setBackViewColor(Color.parseColor("#AA333333"))
                .setOnImageClickListener(new AdManager.OnImageClickListener() {
                    @Override
                    public void onImageClick(View view, AdInfo advInfo) {
                        UIShow.showWebActivity(App.getActivity(), 1, advInfo.getUrl() + "?uid=" +
                                ModuleMgr.getCenterMgr().getMyInfo().getUid());
                    }
                });
        // 执行弹窗的显示操作
        adManager.showAdDialog(AdConstant.ANIM_DOWN_TO_UP);
    }

    // ================================= 商城 ==================================

    /**
     * 获取商品列表
     *
     * @param page 页码，从1开始
     */
    public void reqGoodsList(int page, RequestComplete complete) {
        Map<String, Object> getParam = new HashMap<>();
        getParam.put("limit", 50);
        getParam.put("offset", 50 * (page - 1)); // 查找偏移量
        ModuleMgr.getHttpMgr().reqGetAndCacheHttp(UrlParam.reqGoodsList, getParam, complete);
    }

    /**
     * 兑换商品
     */
    public void reqGoodsExchange(int gid, final int num, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "兑换中...");
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("gid", gid);
        postParam.put("num", num);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqGoodsExchange, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null)
                    complete.onRequestComplete(response);

                LoadingDialog.closeLoadingDialog(200);
                PToast.showShort(response.getMsg());
                if (response.isOk()) {
                    MsgMgr.getInstance().sendMsg(MsgType.MT_Update_MyInfo, null);
                }
            }
        });
    }

    /**
     * 商城： 我的订单
     */
    public void reqGoodsSendList(int page, RequestComplete complete) {
        Map<String, Object> getParam = new HashMap<>();
        getParam.put("limit", 10);
        getParam.put("offset", 10 * (page - 1)); // 查找偏移量
        ModuleMgr.getHttpMgr().reqGetAndCacheHttp(UrlParam.reqGoodsSendList, getParam, complete);
    }

    /**
     * 商城： 我的订单状态更新
     */
    public void reqUpdateStatus(long orderId, int orderStatus, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "删除中...");
        Map<String, Object> getParam = new HashMap<>();
        getParam.put("order_id", orderId);
        getParam.put("order_status", orderStatus); // 查找偏移量
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqUpdateStatus, getParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null) {
                    complete.onRequestComplete(response);
                }

                LoadingDialog.closeLoadingDialog(200);
                PToast.showShort(response.getMsg());
                if (response.isOk()) {
                    MsgMgr.getInstance().sendMsg(MsgType.MT_Store_Order_Refresh, null);
                }
            }
        });
    }

    // ================================= 充值排行榜 ==================================

    /**
     * 获取奖品列表
     *
     * @param page 页码，从1开始
     */
    public void reqAwardList(int page, RequestComplete complete) {
        Map<String, Object> getParam = new HashMap<>();
        getParam.put("limit", 10);
        getParam.put("offset", 10 * (page - 1)); // 查找偏移量
        getParam.put("order_status", "1"); // 查找订单状态
        ModuleMgr.getHttpMgr().reqGetAndCacheHttp(UrlParam.reqAwardList, getParam, complete);
    }

    /**
     * 获取奖品发货列表
     *
     * @param page 页码，从1开始
     */
    public void reqAwardOrderList(int page, RequestComplete complete) {
        Map<String, Object> getParam = new HashMap<>();
        getParam.put("limit", 10);
        getParam.put("offset", 10 * (page - 1)); // 查找偏移量
        getParam.put("order_status", "2,3,4,5,6,7,8,9"); // 查找订单状态
        ModuleMgr.getHttpMgr().reqGetAndCacheHttp(UrlParam.reqAwardList, getParam, complete);
    }

    /**
     * 实体奖品： 奖品发货
     */
    public void reqAwardSend(String ids, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "兑换中...");
        ModuleMgr.getHttpMgr().reqJsonNoCacheHttp(UrlParam.reqAwardSend, ids, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null) {
                    complete.onRequestComplete(response);
                }
                LoadingDialog.closeLoadingDialog(200);
                PToast.showShort(response.getMsg());
            }
        });
    }

    /**
     * 虚拟奖品： 奖品发货
     */
    public void reqAwardRechange(long id, String acount, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "兑换中...");
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("rec_activity_id", id);
        postParam.put("target", acount);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqAwardRechange, postParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null) {
                    complete.onRequestComplete(response);
                }
                LoadingDialog.closeLoadingDialog(200);
                PToast.showShort(response.getMsg());
                if (response.isOk()) {
                    MsgMgr.getInstance().sendMsg(MsgType.MT_Prize_Refresh, null);
                }
            }
        });
    }

    /**
     * 奖品： 我的订单状态更新
     */
    public void reqAwardUpdate(long orderId, int orderStatus, final RequestComplete complete) {
        LoadingDialog.show((FragmentActivity) App.getActivity(), "删除中...");
        Map<String, Object> getParam = new HashMap<>();
        getParam.put("order_id", orderId);
        getParam.put("order_status", orderStatus);
        ModuleMgr.getHttpMgr().reqPostNoCacheHttp(UrlParam.reqAwardUpdate, getParam, new RequestComplete() {
            @Override
            public void onRequestComplete(HttpResponse response) {
                if (complete != null) {
                    complete.onRequestComplete(response);
                }

                LoadingDialog.closeLoadingDialog(200);
                PToast.showShort(response.getMsg());
                if (response.isOk()) {
                    MsgMgr.getInstance().sendMsg(MsgType.MT_Prize_Order_Refresh, null);
                }
            }
        });
    }
}
